package domain

import "time"

var SuccessCode = 0
var ServiceError = 1001

// Rlt  http rlt
type Rlt struct {
	Code      int                    `json:"code"`            // 响应编码:0/200-请求处理成功
	Data      interface{}            `json:"data"`            // 响应数据
	Msg       string                 `json:"msg"`             // 提示消息
	Path      string                 `json:"path"`            // 请求路径
	Extra     map[string]interface{} `json:"extra,omitempty"` // 附加数据
	Timestamp TimeLong               `json:"timestamp"`       // 响应时间戳
	IsSuccess bool                   `json:"isSuccess"`
	IsError   bool                   `json:"isError"`
}

func (r *Rlt) Success() *Rlt {
	r.Code = SuccessCode
	r.Msg = "ok"
	r.IsSuccess = true
	r.IsError = false
	r.Timestamp = TimeLong(time.Now())
	return r
}

func (r *Rlt) Fail(code int, msg string) *Rlt {
	r.Code = code
	r.Msg = msg
	r.IsSuccess = false
	r.IsError = true
	r.Timestamp = TimeLong(time.Now())
	return r
}

func (r *Rlt) SetData(d interface{}) *Rlt {
	r.Data = d
	return r
}
